package com.zhongkai.service.config;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zhongkai.dao.config.RoleDAO;
import com.zhongkai.dao.config.UserDAO;
import com.zhongkai.model.config.User;
import com.zhongkai.service.BaseService;


@Component
@Transactional
public class UserService extends BaseService {

	private UserDAO userDAO;
	private RoleDAO roleDAO;
	
	@Resource
	public void setRoleDAO(RoleDAO roleDAO) {
		this.roleDAO = roleDAO;
	}

	@Resource
	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}


	/*查找所有*/
	public List findAll() throws Exception {
		return userDAO.findAll();
	}
	
	
	public void save(User user) throws Exception{
		userDAO.save(user);
	}

	public void delete(User user) throws Exception {
		userDAO.delete(user);
	}

	public User findById(java.lang.Integer id) throws Exception {
		
		return userDAO.findById(id);
	}
/**
 * 根据账号查找用户
 * @param account
 * @return
 * @throws Exception
 */
	public User findByAccount(String account) throws Exception {
		return userDAO.findByAccount(account);
	}
/**
 * 判断是否存在某用户
 * @param user
 * @return
 * @throws Exception
 */
	public boolean exist(User user) throws Exception {
		return userDAO.exist(user);
	}
	
	public List findByExample(User user) throws Exception {
		
		return userDAO.findByExample(user);
	}

	public List findByProperty(String propertyName, Object value) throws Exception {
		
		return userDAO.findByProperty(propertyName, value);
	}
	public User merge(User user) throws Exception {
		
		return userDAO.merge(user);
	}
	
	public void update(User user) throws Exception {
		
		userDAO.update(user);
	}
	

	public void attachDirty(User admin) throws Exception {
		userDAO.attachDirty(admin);
	}

	public void attachClean(User admin) throws Exception {
		userDAO.attachClean(admin);
	}

	public static UserDAO getFromApplicationContext(ApplicationContext ctx) {
		return (UserDAO) ctx.getBean("userDAO");
	}
	
/**
 *  根据属性组查找
 * @param hql
 * @param values
 * @return
 * @throws Exception
 */	 
	public List findByHql(String hql, Object[] values) throws Exception {
		return userDAO.findByHql(hql, values);
	}
}
